package com.ruicar.afs.cloud.workflow.gwt.controller;

import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.workflow.api.dto.afsprocess.request.*;
import com.ruicar.afs.cloud.workflow.gwt.componts.GwtWorkFlowService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * The type GwtWorkFlowController
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.07.08 17:25:22
 * @since 1.0
 */
@RestController
@RequestMapping("/workflow/api")
@AllArgsConstructor
public class GwtWorkFlowController {
    /**
     * Check user online response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/checkUserOnline")
    public IResponse checkUserOnline(@RequestBody AfsFlowQueryRequest<UserOnlineRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).checkUserOnline(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").checkUserOnline(afsFlowQueryRequest.getData()));
        }
    }

    /**
     * Get assign user response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/getAssignUser")
    public IResponse getAssignUser(@RequestBody AfsFlowQueryRequest<GetAssignUserRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).getAssignUser(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").getAssignUser(afsFlowQueryRequest.getData()));
        }
    }


    /**
     * Query org condition response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/queryOrgCondition")
    public IResponse queryOrgCondition(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).queryOrgCondition(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").queryOrgCondition(afsFlowQueryRequest.getData()));
        }
    }

    /**
     * Query roles response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/queryRoles")
    public IResponse queryRoles(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).queryRole(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").queryRole(afsFlowQueryRequest.getData()));
        }
    }

    /**
     * Query user info response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/queryUserInfo")
    public IResponse queryUserInfo(@RequestBody AfsFlowQueryRequest<QueryCondition> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).queryUserInfo(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").queryUserInfo(afsFlowQueryRequest.getData()));
        }
    }


    /**
     * Task create response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/taskCreate")
    public IResponse taskCreate(@RequestBody AfsFlowQueryRequest<TaskCreateRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.NOTICE_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).taskCreated(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").taskCreated(afsFlowQueryRequest.getData()));
        }
    }

    /**
     * Task assign response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/taskAssign")
    public IResponse taskAssign(@RequestBody AfsFlowQueryRequest<TaskAssignRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.NOTICE_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).taskAssigned(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").taskAssigned(afsFlowQueryRequest.getData()));
        }
    }

    /**
     * Update biz data response
     *
     * @param afsFlowQueryRequest afs flow request
     * @return the response
     */
    @PostMapping("/updateBizData")
    public IResponse updateBizData(@RequestBody AfsFlowQueryRequest<UpdateBizDataRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.NOTICE_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).updateBizData(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").updateBizData(afsFlowQueryRequest.getData()));
        }
    }


    @PostMapping("/getRtnUserInfo")
    public IResponse getRtnUserInfo(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).getRtnUserInfo(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").getRtnUserInfo(afsFlowQueryRequest.getData()));
        }
    }

    @PostMapping("/getApplyUserInfo")
    public IResponse getApplyUserInfo(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).getApplyUserInfo(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").getApplyUserInfo(afsFlowQueryRequest.getData()));
        }
    }

    @PostMapping("/getLeader")
    public IResponse getLeader(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).getLeader(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").getLeader(afsFlowQueryRequest.getData()));
        }
    }

    @PostMapping("/getOperUser")
    public IResponse getOperUser(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).getOperUser(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").getOperUser(afsFlowQueryRequest.getData()));
        }
    }

    @PostMapping("/commonNodeCheckUser")
    public IResponse commonNodeCheckUser(@RequestBody AfsFlowQueryRequest<CommonGetRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).commonNodeCheckUser(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.QUERY_PROCESSOR.get("default").commonNodeCheckUser(afsFlowQueryRequest.getData()));
        }
    }


    @PostMapping("/taskAssignError")
    public IResponse taskAssignError(@RequestBody AfsFlowQueryRequest<FlowExceptionRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).assignError(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").assignError(afsFlowQueryRequest.getData()));
        }
    }



    @PostMapping("/dataGetError")
    public IResponse dataGetError(@RequestBody AfsFlowQueryRequest<FlowExceptionRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).dataGetError(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").dataGetError(afsFlowQueryRequest.getData()));
        }
    }

    @PostMapping("/defaultError")
    public IResponse defaultError(@RequestBody AfsFlowQueryRequest<FlowExceptionRequest> afsFlowQueryRequest) {
        if (GwtWorkFlowService.QUERY_PROCESSOR.containsKey(afsFlowQueryRequest.getAfsFlowKey())) {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get(afsFlowQueryRequest.getAfsFlowKey()).defaultError(afsFlowQueryRequest.getData()));
        } else {
            return IResponse.success(GwtWorkFlowService.NOTICE_PROCESSOR.get("default").defaultError(afsFlowQueryRequest.getData()));
        }
    }
}
